package com.rmt.www.serviceImpl;

import java.util.List;

import com.rmt.www.dao.DesignArtifactHistoryDao;
import com.rmt.www.dao.FeatureArtifactHistoryDao;
import com.rmt.www.dao.ImplementationArtifactHistoryDao;
import com.rmt.www.dao.RequirementArtifactHistoryDao;
import com.rmt.www.dao.TestArtifactHistoryDao;
import com.rmt.www.dao.UserDao;
import com.rmt.www.service.HistoryService;
import com.rmt.www.vo.DesignArtifact;
import com.rmt.www.vo.DesignArtifactHistory;
import com.rmt.www.vo.FeatureArtifact;
import com.rmt.www.vo.FeatureArtifactHistory;
import com.rmt.www.vo.ImplementationArtifact;
import com.rmt.www.vo.ImplementationArtifactHistory;
import com.rmt.www.vo.RequirementArtifact;
import com.rmt.www.vo.RequirementArtifactHistory;
import com.rmt.www.vo.TestArtifact;
import com.rmt.www.vo.TestArtifactHistory;

public class HistoryServiceImpl implements HistoryService {
	
	private FeatureArtifactHistoryDao featureArtifactHistoryDao;
	
	private RequirementArtifactHistoryDao requirementArtifactHistoryDao;
	
	private DesignArtifactHistoryDao designArtifactHistoryDao;
	
	private ImplementationArtifactHistoryDao implementationArtifactHistoryDao;
	
	private TestArtifactHistoryDao testArtifactHistoryDao;

	private UserDao userDao;
	
	public List<DesignArtifactHistory> getDesignHistoryList(int aid) {
		List<DesignArtifactHistory> list = designArtifactHistoryDao.getDesignArtifactHistoriesByAId(aid);
		int authorid, updaterid;
		for (int i = 0; i < list.size(); i++) {
			authorid = list.get(i).getCreaterid();
			updaterid = list.get(i).getUpdaterid();
			list.get(i).set_authorname(userDao.getUser(authorid).getName());
			if (updaterid != 0)
				list.get(i).set_updatername(userDao.getUser(updaterid).getName());
		}
		return list;
	}

	public List<FeatureArtifactHistory> getFeatureHistoryList(int aid) {
		List<FeatureArtifactHistory> list = featureArtifactHistoryDao.getFeatureArtifactHistoriesById(aid);
		int authorid, updaterid;
		for (int i = 0; i < list.size(); i++) {
			authorid = list.get(i).getAuthorId();
			updaterid = list.get(i).getUpdateUserId();
			list.get(i).set_authorname(userDao.getUser(authorid).getName());
			if (updaterid != 0)
				list.get(i).set_updatername(userDao.getUser(updaterid).getName());
		}
		return list;
	}

	public List<ImplementationArtifactHistory> getImplementationHistory(int aid) {
		List<ImplementationArtifactHistory> list = implementationArtifactHistoryDao.getImplementationArtifactHistoryById(aid);
		int authorid, updaterid;
		for (int i = 0; i < list.size(); i++) {
			authorid = list.get(i).getCreaterid();
			updaterid = list.get(i).getUpdaterid();
			list.get(i).set_authorname(userDao.getUser(authorid).getName());
			if (updaterid != 0)
				list.get(i).set_updatername(userDao.getUser(updaterid).getName());
		}
		return list;
	}

	public List<RequirementArtifactHistory> getRequirementHistoryList(int aid) {
		List<RequirementArtifactHistory> list = requirementArtifactHistoryDao.getRequirementArtifactHistoryById(aid);
		int authorid, updaterid;
		for (int i = 0; i < list.size(); i++) {
			authorid = list.get(i).getAuthorId();
			updaterid = list.get(i).getUpdateUserId();
			list.get(i).set_authorname(userDao.getUser(authorid).getName());
			if (updaterid != 0)
				list.get(i).set_updatername(userDao.getUser(updaterid).getName());
		}
		return list;
	}

	public List<TestArtifactHistory> getTestArtifactHistory(int aid) {
		List<TestArtifactHistory> list = testArtifactHistoryDao.getTestArtifactHistoriesById(aid);
		int authorid, updaterid;
		for (int i = 0; i < list.size(); i++) {
			authorid = list.get(i).getCreaterid();
			updaterid = list.get(i).getUpdaterid();
			list.get(i).set_authorname(userDao.getUser(authorid).getName());
			if (updaterid != 0)
				list.get(i).set_updatername(userDao.getUser(updaterid).getName());
		}
		return list;
	}

	public FeatureArtifactHistoryDao getFeatureArtifactHistoryDao() {
		return featureArtifactHistoryDao;
	}

	public void setFeatureArtifactHistoryDao(
			FeatureArtifactHistoryDao featureArtifactHistoryDao) {
		this.featureArtifactHistoryDao = featureArtifactHistoryDao;
	}

	public RequirementArtifactHistoryDao getRequirementArtifactHistoryDao() {
		return requirementArtifactHistoryDao;
	}

	public void setRequirementArtifactHistoryDao(
			RequirementArtifactHistoryDao requirementArtifactHistoryDao) {
		this.requirementArtifactHistoryDao = requirementArtifactHistoryDao;
	}

	public DesignArtifactHistoryDao getDesignArtifactHistoryDao() {
		return designArtifactHistoryDao;
	}

	public void setDesignArtifactHistoryDao(
			DesignArtifactHistoryDao designArtifactHistoryDao) {
		this.designArtifactHistoryDao = designArtifactHistoryDao;
	}

	public ImplementationArtifactHistoryDao getImplementationArtifactHistoryDao() {
		return implementationArtifactHistoryDao;
	}

	public void setImplementationArtifactHistoryDao(
			ImplementationArtifactHistoryDao implementationArtifactHistoryDao) {
		this.implementationArtifactHistoryDao = implementationArtifactHistoryDao;
	}

	public TestArtifactHistoryDao getTestArtifactHistoryDao() {
		return testArtifactHistoryDao;
	}

	public void setTestArtifactHistoryDao(
			TestArtifactHistoryDao testArtifactHistoryDao) {
		this.testArtifactHistoryDao = testArtifactHistoryDao;
	}

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

}
